package _01_动态数组;

public class _268_丢失的数字 {

    public static void main(String[] args) {

        _268_丢失的数字 v = new _268_丢失的数字();
        int[] ins = {3, 0, 1};
        System.out.println(v.missingNumber(ins));

    }

    // 位运算
    public int missingNumber(int[] nums) {
        int results = 0;
        for (int num : nums) {
            results ^= num;
        }
        int len = nums.length;
        for (int i = 0; i <= len; i++) {
            results ^= i;
        }
        return results;
    }

    // 等差求和
    public int missingNumber1(int[] nums) {
        int len = nums.length;
        int result = (len * (len + 1)) >> 1;

        for (int num : nums) {
            result -= num;
        }
        return result;
    }

}
